package com.murong.ai.coder.domain;

import com.murong.ai.coder.entity.GlobalProperties;
import com.murong.ai.coder.infrastructure.view.SqlExecWindow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.swing.*;

@Service
public class WindowService {
    @Autowired
    private GlobalProperties globalProperties;

    private SqlExecWindow sqlWindow;

    public void openSqlExecWindow() {
        if (sqlWindow == null || !sqlWindow.isDisplayable()) {
            SwingUtilities.invokeLater(() -> {
                sqlWindow = new SqlExecWindow(globalProperties);
                sqlWindow.setVisible(true);
            });
        }else if(sqlWindow != null){
            sqlWindow.setVisible(true);
        }
    }

    public void closeWindow() {
        if (sqlWindow != null && sqlWindow.isDisplayable()) {
            SwingUtilities.invokeLater(() -> {
                sqlWindow.dispose();
            });
        }
    }
} 